package com.bw.rbac.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bw.rbac.entity.SearchTrain;
import com.bw.rbac.entity.Trainv;
import com.bw.rbac.service.ITrainvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * VIEW 前端控制器
 * </p>
 *
 * @author 青山
 * @since 2022-05-27
 */
@RestController
@RequestMapping("/trainv")
public class TrainvController {
    @Autowired
    ITrainvService iTrainvService;


    @RequestMapping("/listTrainv")
    public Page<Trainv> listTrain(@RequestBody SearchTrain searchTrain) {

        // 分页
        Page<Trainv> trainPage = new Page<>(searchTrain.getPage(),searchTrain.getPageSize());
        QueryWrapper<Trainv> wrapper =new QueryWrapper<>();
        // 模糊查询
        //始发站
        if(StringUtils.hasText(searchTrain.getBegin())){
            wrapper.like("begin", searchTrain.getBegin());
        }
        //乘车日期
        if(searchTrain.getByTime1()!=null){
            wrapper.gt("by_time",searchTrain.getByTime1());
        }
        if(searchTrain.getByTime2()!=null){
            wrapper.lt("by_time",searchTrain.getByTime2());
        }
        // 姓名
        if(StringUtils.hasText(searchTrain.getName())){
            wrapper.like("name", searchTrain.getName());
        }
        Page<Trainv> page = iTrainvService.page(trainPage, wrapper);
        return page;
    }

}
